import 'package:yaml/yaml.dart';

import 'asset_config.dart';

class ResConfig {
  String package;
  String name;
  ResDark dark;
  ResJson json;
  AssetConfig? assetConfig;
  ResIntl? resIntl;

  ResConfig({
    this.package = "lib/resource",
    this.name = "resources",
    required this.dark,
    required this.json,
    this.assetConfig,
    this.resIntl,
  });

  factory ResConfig.fromYaml(YamlMap yamlMap) {
    return ResConfig(
      package: yamlMap['package'] ?? 'lib/resource',
      name: yamlMap['name'] ?? 'resources',
      dark: ResDark.fromYaml(yamlMap['dark']),
      json: ResJson.fromYaml(yamlMap['json']),
      assetConfig: AssetConfig.fromYaml(yamlMap['asset']),
      resIntl: ResIntl.fromYam(yamlMap['intl']),
    );
  }
}

class ResDark {
  bool enable;
  String import;
  String condition;

  ResDark({this.enable = true, this.import = "", this.condition = ""});

  factory ResDark.fromYaml(YamlMap? yamlMap) {
    return ResDark(
        enable: yamlMap?['enable'] ?? true,
        import: yamlMap?['import'] ??
            "import 'package:lib_uikit/theme/gt_theme_provider.dart';",
        condition:
            yamlMap?['condition'] ?? "GTThemeProvider.instance.isDark()");
  }
}

class ResJson {
  String resource;
  String package;
  bool jsonKey;
  bool camelCase;
  bool skipIfExit;
  bool safelyConvert;
  YamlList? keys;

  ResJson({
    this.resource = 'lib/json',
    this.jsonKey = true,
    this.camelCase = true,
    this.package = 'lib/models',
    this.skipIfExit = false,
    this.safelyConvert = false,
    this.keys,
  });

  factory ResJson.fromYaml(YamlMap? yamlMap) {
    return ResJson(
        resource: yamlMap?['resource'] ?? 'lib/json',
        jsonKey: yamlMap?['json_key'] ?? true,
        camelCase: yamlMap?['camel_case'] ?? true,
        package: yamlMap?['package'] ?? 'lib/models',
        skipIfExit: yamlMap?['skip_if_exit'] ?? false,
        safelyConvert: yamlMap?['safely_convert'] ?? false,
        keys: yamlMap?['keys']);
  }
}

class ResIntl {
  String path;
  String defLang;
  YamlList? ignoreLang;
  YamlList? ignoreKey;

  ResIntl({
    this.path = 'lib/l10n',
    this.defLang = 'intl_en',
    this.ignoreLang,
    this.ignoreKey,
  });

  factory ResIntl.fromYam(YamlMap? yamlMap) {
    return ResIntl(
      path: yamlMap?['path'] ?? 'lib/l10n',
      defLang: yamlMap?['default_lang'] ?? 'intl_en',
      ignoreLang: yamlMap?['ignore_lang'],
      ignoreKey: yamlMap?['ignore_key'],
    );
  }
}
